/*
 * Name: Joon Ho Cho
 * Date: 10/24/2008
 * Course: 15-437
 */
package scheduler.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import scheduler.databean.User;
import scheduler.formbean.LoginForm;
import scheduler.model.Model;


public class CurrentScheduleAction extends Action {
	Model model;
	public CurrentScheduleAction(Model model) {
		this.model=model;
	}

	public String getName() { return "current.do"; }
    
    public String perform(HttpServletRequest request) {
    	
    	 HttpSession session = request.getSession(true); 
	        User user = (User) session.getAttribute("user");
	        
	        if (user == null) {
				LoginForm form = new LoginForm();
				form.setRedirect("/add-bookmark.do");
		        request.setAttribute("form",form);
				return "login.jsp";
			} 
	        if(user.getNumSchedule()==0)
	        {
	        	return "create.do";
	        }
	        System.out.println("Current Schedule="+user.getCurrentSchedule());
	        request.getSession().setAttribute("scheduleID", user.getCurrentSchedule());  			
			return "schedule.do";	 	
    	
    }
}
